<template>
  <div>
    <van-nav-bar
      fixed
      left-arrow
      @click-left="$router.back()"
      :title="`${$route.query.q}的搜索结果`"
      placeholder
    ></van-nav-bar>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell v-for="item in list" :key="item.art_id" :title="item.title" @click="$router.push({path:'/article',query:{id:item.art_id}})" />
    </van-list>
  </div>
</template>

<script>
import { getResult } from './home.js'
export default {
  name: 'searchResult',
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 1,
      per_page: 10,
    }
  },
  methods: {
    async onLoad () {
      let res = await getResult({q: this.$route.query.q,page: this.page,per_page:this.per_page})
      console.log(res);
      this.list.push(...res.data.data.results)
      this.page++
      this.loading = false
      if (res.data.data.results.length == 0) {
        this.finished = true
      }
    }
  }
}
</script>

<style></style>
